<?php
	error_reporting(0);
	session_start();
	include 'constants.php';
	mysql_connect($host, $user, $pass);
	mysql_select_db($base);
	// $conn = new mysqli($host, $user, $pass, $base);
	
	function head() {
		echo <<<BDPA
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<title>BDPA-NY Vending Machine Application</title>
			<link rel="stylesheet" href="style.css" type="text/css" />
			<script src="script.js"></script>
		</head>
		<body>
		<div id=main>
			<div id=links></div>
			<div id=header>
				<div id=logo>
					<div id=logo_text>
						<h1>BDPA-NY</h1>
						<h2>Vending Machine Application</h2>
					</div>
				</div>
				<div id=menubar>
					<ul id=menu>
BDPA;
		if(isset($_SESSION['id'])) {
			echo <<<BDPA
						<li><a href=main.php>Home</a></li>
						<li><a href=base.php>Create Order</a></li>
						<li><a href=cust.php>Customize Order</a></li>
						<li><a href=checkout.php>Checkout</a></li>
						<li><a href=order.php>Receipts</a></li>
						<li><a href=about.php>About US</a></li>
						<li><a href='#' onclick='logout()'>Logout</a></li>
BDPA;
			/*echo <<<BDPA
						<li><a href=main.php>Home</a></li>
						<li><a href=base.php>Create Order</a></li>
						<li><a href=cust.php>Customize Order</a></li>
						<li><a href=checkout.php>Checkout</a></li>
						<li><a href='#' class="na">Receipts</a></li>
						<li><a href=about.php>About US</a></li>
						<li><a href='#' onclick='logout()'>Logout</a></li>
BDPA;*/
		}
		else {
			echo <<<BDPA
						<li><a href=index.php>Home</a></li>
						<li><a href=register.php>Register</a></li>
						<li><a href=about.php>About US</a></li>
BDPA;
		}
		echo <<<BDPA
					</ul>
				</div>
			</div>
			<div id=site_content>
BDPA;
		if(isset($_SESSION['id'])) {
			$id=$_SESSION['id'];
			$date=date("Y-m-d H:i:s");
			if((isset($_SESSION['oid']) && isset($reset)) || !isset($_SESSION['oid'])) {
				$oid=$_SESSION['oid'];
				/*
				$query = "DELETE FROM orderacc WHERE OrderAcc_ID='{$oid}'";
				$conn->query($query);
				*/
				mysql_query("delete from orderacc where OrderAcc_ID={$oid}");	
				unset($_SESSION['oid']);
				unset($oid);
					$order;
			}
			else {
				$order="Order ID: ".$_SESSION['oid'];
			}
			echo <<<BDPA
			<div class=sidebar>
				<h3>Customer ID: $id</h3>
				<h3>Date: $date</h3>
BDPA;
			if (isset($_SESSION["oid"])) {
				echo "<h3>Order ID: {$_SESSION["oid"]}</h3>";
			}
			$id=$_SESSION['id'];
			$query=mysql_query("select * from orderconfig where OA_Cust_ID={$id} ORDER BY OrderAcc_ID");
			if(mysql_num_rows($query) > 0) {
				echo <<<BDPA
				<h3>Previous Orders</h3>
				<table>
				<th>Order ID</th><th>Order Date</th>
BDPA;
				while($row=mysql_fetch_array($query)) {
					extract($row);
					echo <<<BDPA
					<tr><td>
					$OrderAcc_ID
					</td><td>
					$OrderAcc_Date
					</td></tr>
BDPA;
				}
				echo "</table>";
			}
			else {
				echo <<<BDPA
				No Previous Orders
BDPA;
			}
			echo "</div>";
		}
		echo <<<BDPA
		<div id=content>
BDPA;
	}
	
	function foot() {
		echo <<<BDPA
		</div>
		<div id=site_content_bottom></div>
		</div>
		<div id=footer><center>Copyright &copy;BDPA-NY Option Explicit 2013</center></div>
		</div>
BDPA;
	}
?>